package com.bjpowernode.service.impl;

import com.alibaba.excel.EasyExcel;
import com.bjpowernode.config.listener.DemoDataListener;
import com.bjpowernode.constant.Constants;
import com.bjpowernode.entity.TClue;
import com.bjpowernode.entity.dto.TClueDO;
import com.bjpowernode.mapper.TClueMapper;
import com.bjpowernode.service.TClueService;
import com.bjpowernode.utils.JwtUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

/**
 *
 */
@Service
@Slf4j
public class TClueServiceImpl implements TClueService {

    @Resource
    private TClueMapper tClueMapper;

    @Resource
    private JwtUtil jwtUtil;

    @Override
    public PageInfo<TClue> getClueByPage(Integer current) {
        // 开启分页功能
        PageHelper.startPage(current, Constants.PAGE_SIZE);
        // 查询
        List<TClue> tClueList = tClueMapper.selectClue();
        // 封装pageInfo
        PageInfo<TClue> pageInfo = new PageInfo<>(tClueList);
        return pageInfo;
    }

    @Override
    public void importExcel(InputStream inputStream, String jwt) {
        EasyExcel
                .read(inputStream,
                        TClueDO.class,
                        new DemoDataListener(tClueMapper, jwtUtil, jwt))
                .sheet()
                .doRead();
    }

    @Override
    public TClue loadClueDetail(Integer id) {
        TClue tClue = tClueMapper.getClueById(id);
        return tClue;
    }

    @Override
    public int updateClueState(TClue tClue) {
        return tClueMapper.updateByPrimaryKeySelective(tClue);
    }

    @Override
    public TClue selectClueById(Integer clueId) {
        return tClueMapper.selectByPrimaryKey(clueId);
    }

    @Override
    public int removeById(Integer id) {
        return tClueMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int batchRemove(List<Integer> idList) {
        return tClueMapper.batchRemove(idList);
    }
}
